﻿var btnState = 0, saveState = 0;

$(document).ready(function () {
    //决策人手机只能为数字
    $("#DecisionTel").keypress(function (e) {
        //注意此处不要用keydown方法，否则不能禁用Ctrl+C与Ctrl+V,具体原因请自行查找keyPress与keyDown区分，十分重要，请细查
        if ($.browser.msie) {  //判断浏览器
            if (((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 8)) { //判断键值 
                return true;
            } else {
                return false;
            }
        } else {
            if (((e.which > 47) && (e.which < 58)) || (e.which == 8) || (event.keyCode == 17)) {
                return true;
            } else {
                return false;
            }
        }
    }).focus(function () {
        this.style.imeMode = 'disabled'; //禁用输入法,禁止输入中文字符
    }).bind("paste", function () {
        //alert($("#text").val());
        //return false;
    }).keyup(function (e) {
        _v = $("#DecisionTel").val();
        for (_i = 0; _i < _v.length; _i++) {
            _c = _v.charAt(_i);
            if (isNaN(_c)) {
                $("#DecisionTel").val("");
                return;
            }
        }
    });

    $('#Province').change(function () {
        var vProvince = $(this).children('option:selected').val();
        if (vProvince != "") {
            document.getElementById("City").options.length = 0;
            document.getElementById("Area").options.length = 0;
            $("#City").append("<option value=''>选择城市</option>");
            $("#Area").append("<option value=''>选择区县</option>");
            var vc = "ProvinceId='" + vProvince + "'";
            YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/JSONList.aspx?type=1&entity=SysCity&customCondition=" + vc + "", //条件 
                            {success: function (res) {
                                try {
                                    var str = res.responseText;
                                    var obj = eval(str);
                                    for (var i = 0; i < obj.length; i++) {
                                        if (obj[i].Code != undefined || obj[i].Name != undefined) {
                                            $("#City").append("<option value='" + obj[i].Code + "'>" + obj[i].Name + "</option>");
                                        }
                                    }
                                }
                                catch (e) {
                                }
                                finally {
                                }
                            }, failure: function () { }
                        });
        }
    });
    $('#City').change(function () {
        var vCity = $('#City').children('option:selected').val();
        if (vCity != "") {
            document.getElementById("Area").options.length = 0;
            $("#Area").append("<option value=''>选择区县</option>");
            var vc = "CityId='" + vCity + "'";
            YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/JSONList.aspx?type=1&entity=SysArea&customCondition=" + vc + "", //条件 
                            {success: function (res) {
                                try {
                                    var str = res.responseText;
                                    var obj = eval(str);
                                    for (var i = 0; i < obj.length; i++) {
                                        $("#Area").append($("<option></option>").val(obj[i].Name).html(obj[i].Name));
                                    }
                                }
                                catch (e) {
                                }
                                finally {
                                }
                            }, failure: function () { }
                        });
        }
    });
})

YAHOO.example.init = function () {
    function onButtonClick(p_oEvent) {
        switch (this.get("id")) {
            case "btnSave":
                Save();
                break;
            case "btnModify":
                Modify();
                break;
            case "btnClose":
                fnClose();
                break;
            default:
                break;
        }
    }
    YAHOO.util.Event.onContentReady("toolbar", function () {
        btnSave = new YAHOO.widget.Button("btnSave");
        btnSave.on("click", onButtonClick);
        btnModify = new YAHOO.widget.Button("btnModify");
        btnModify.on("click", onButtonClick);
        btnClose = new YAHOO.widget.Button("btnClose");
        btnClose.on("click", onButtonClick);
        btnSCustomer = new YAHOO.widget.Button("btnSCustomer");
        btnSCustomer.on("click", onButtonClick);
        btnPrivateCustomer = new YAHOO.widget.Button("btnPrivateCustomer");
        btnPrivateCustomer.on("click", onButtonClick);
        if (flag == "0") {  //查看状态
            btnSave._button.style.display = "none";
            $("#btnSave").attr('disabled', "true");
            document.getElementById("btnAddLinkMan").style.display = "none";
            document.getElementById("btnDeleteLinkMan").style.display = "none";
            document.getElementById("btnAddLinkRecord").style.display = "none";
            document.getElementById("btnDeleteLinkRecord").style.display = "none";
            document.getElementById("btnAddAttach").style.display = "none";
            document.getElementById("btnDeleteAttach").style.display = "none";
            document.getElementById("btnAddCustomerRelation").style.display = "none";
            document.getElementById("btnDeleteCustomerRelation").style.display = "none";
        } else if (flag == "2" || flag == "1" || flag == "3" || flag=="4") {  //编辑/新增状态/录入客户
            btnModify._button.style.display = "none";
            $("#btnModify").attr('disabled', "true");
        } else {
            btnSave._button.style.display = "none";
            $("#btnSave").attr('disabled', "true");
            btnModify._button.style.display = "none";
            $("#btnModify").attr('disabled', "true");
            document.getElementById("btnAddLinkMan").style.display = "none";
            document.getElementById("btnDeleteLinkMan").style.display = "none";
            document.getElementById("btnAddLinkRecord").style.display = "none";
            document.getElementById("btnDeleteLinkRecord").style.display = "none";
            document.getElementById("btnAddAttach").style.display = "none";
            document.getElementById("btnDeleteAttach").style.display = "none";
            document.getElementById("btnAddCustomerRelation").style.display = "none";
            document.getElementById("btnDeleteCustomerRelation").style.display = "none";
        }
    });
} ();
var _DialogState = "";
YAHOO.namespace("example.container");
YAHOO.util.Event.onDOMReady(function () {
    var handleSubmit1 = function () {
        var editwindow = document.getElementById("EditUIWindow1");
        if (editwindow) {
            if (_id == "btnAddUserName" || _id == "btnLectorName" ||
                _id == "btnSaleadviserId" || _id == "btnCustomeerMgrs" ||
                _id == "btnRelationCustomerName") {
                editwindow.contentWindow.ChooseInfo();
            } else {
                editwindow.contentWindow.Save();
            }
        }
        YAHOO.example.container.dialog1.hide();
    };
    var handleSubmit2 = function () {
        var editwindow = document.getElementById("EditUIWindow2");
        if (editwindow) {
            editwindow.contentWindow.SaveAttach();
        }
    }
    var handleSubmit3 = function () {
        var editwindow = document.getElementById("EditUIWindow2");
        if (editwindow) {
            editwindow.contentWindow.SaveAttach();
        }
        YAHOO.example.container.dialog2.hide();
    }
    var handleSubmit4 = function () {
        var editwindow = document.getElementById("EditUIWindow3");
        if (editwindow) {
            editwindow.contentWindow.Save();
        }
    }
    var handleSubmit5 = function () {
        var editwindow = document.getElementById("EditUIWindow3");
        if (editwindow) {
            editwindow.contentWindow.Save();
        }
        if (_DialogState == "") {
            YAHOO.example.container.dialog3.hide();
            return;
        }
    }
    var handleSubmit6 = function () {
        var editwindow = document.getElementById("EditUIWindow4");
        if (editwindow) {
            Save();
        }
        YAHOO.example.container.dialog4.hide();
    }
    var handleCancel = function () {
        this.cancel();
    };
    var handleSuccess = function (o) {
        var response = o.responseText;
        response = response.split("<!")[0];
        document.getElementById("resp").innerHTML = response;
    };
    var handleFailure = function (o) {
        alert("Submission failed: " + o.status);
    };
    YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1",
					        { width: "640px",
					            height: "300px",
					            xy: [10, 10],
					            fixedcenter: false,
					            visible: false,
					            draggable: true,
					            modal: true,
					            close: true,
					            autofillheight: "body",
					            constraintoviewport: true,
					            buttons: [{ text: "确定", handler: handleSubmit1, isDefault: true },
								        { text: "取消", handler: handleCancel}]
					        });
    YAHOO.example.container.dialog2 = new YAHOO.widget.Dialog("dialog2",
					        { width: "420px",
					            height: "280px",
					            fixedcenter: true,
					            visible: false,
					            draggable: true,
					            modal: true,
					            close: true,
					            autofillheight: "body",
					            constraintoviewport: true,
					            buttons: [{ text: "保存并新建", handler: handleSubmit2, isDefault: true },
					            /*{ text: "保存", handler: handleSubmit3 },*/
								        {text: "取消", handler: handleCancel}]
					        });
    YAHOO.example.container.dialog3 = new YAHOO.widget.Dialog("dialog3",
					        { width: "450px",
					            height: "360px",
					            fixedcenter: true,
					            visible: false,
					            draggable: true,
					            modal: true,
					            close: true,
					            autofillheight: "body",
					            constraintoviewport: true,
					            buttons: [{ text: "保存退出", handler: handleSubmit5, isDefault: true },
                                        { text: "保存并新建", handler: handleSubmit4 },
								        { text: "取消", handler: handleCancel}]
					        });
    YAHOO.example.container.dialog4 = new YAHOO.widget.Dialog("dialog4",
					        { width: "640px",
					            height: "300px",
					            xy: [10, 10],
					            fixedcenter: false,
					            visible: false,
					            draggable: false,
					            modal: true,
					            close: true,
					            autofillheight: "body",
					            constraintoviewport: true,
					            buttons: [{ text: "继续保存", handler: handleSubmit6, isDefault: true },
								        { text: "取消", handler: handleCancel}]
					        });
    YAHOO.example.container.dialog1.callback = { success: handleSuccess, failure: handleFailure };
    YAHOO.example.container.dialog1.render();
    YAHOO.example.container.dialog2.render();
    YAHOO.example.container.dialog3.render();
    YAHOO.example.container.dialog4.render();
});
/* 对应的方法和ID*/
var _fn, _id;
function ShowDialog(fn, id, src) {
    _fn = fn;
    _id = id;
    document.getElementById("EditUIWindow1").src = src;
    SetMaxDWH(YAHOO.example.container.dialog1, 50, 50);
    YAHOO.example.container.dialog1.show();
}
// 设窗口最大化
var SetMaxDWH = function (dialog, width, height) {
    var w = Y.util.Dom.getViewportWidth() - width;
    var h = Y.util.Dom.getViewportHeight() - height;
    SetDWH(w, h, dialog);
}
// 设置对话框的大小
var SetDWH = function (width, height, dialog) {
    var elements = YAHOO.util.Dom.getElementsByClassName('bd', 'div')[0];
    var w = [],
            h = [];
    w.push(width);
    h.push(height);
    dialog.configWidth(null, w);
    dialog.configHeight(null, h);
    dialog.render();
    if (elements) {
        dialog.fillHeight(elements);
    }
}

YAHOO.util.Event.addListener(window, "load", function () {
    BindData1();
    BindData2();
    BindData3();
    BindData4();
    BindData5();
    BindData6();
    BindData7();
    BindData8();
    BindData9();
    BindData10();
    BindData11();
    BindData12();
    hideCol();
});
var formatAttach = function (elCell, oRecord, oColumn, sData) {
    if (sData == null) {
        elCell.innerHTML = "";
    } else {
        elCell.innerHTML = "<a href='../../EditWidows/DownLoad.aspx?filename=" + sData + "' style='color:#000000;'>下载附件</a>";
    }
}
var formatSex = function (elCell, oRecord, oColumn, sData) {
    if (sData == null || sData == "") {
        elCell.innerHTML = "";
    } else if (sData == "M") {
        elCell.innerHTML = "男";
    } else if (sData == "F") {
        elCell.innerHTML = "女";
    }
}
var formatContents2 = function (elCell, oRecord, oColumn, sData) {
    if (sData.length > 12) {
        elCell.innerHTML = sData.substring(0, 12) + "...";
    } else {
        elCell.innerHTML = sData;
    }
}
var formatExplain2 = function (elCell, oRecord, oColumn, sData) {
    if (sData.length > 12) {
        elCell.innerHTML = sData.substring(0, 12) + "...";
    } else {
        elCell.innerHTML = sData;
    } formatExplain2
}
var formatAnticipeResult6 = function (elCell, oRecord, oColumn, sData) {
    if (sData.length > 8) {
        elCell.innerHTML = sData.substring(0, 8) + "...";
    } else {
        elCell.innerHTML = sData;
    } formatExplain2
}
var formatContents6 = function (elCell, oRecord, oColumn, sData) {
    if (sData.length > 8) {
        elCell.innerHTML = sData.substring(0, 8) + "...";
    } else {
        elCell.innerHTML = sData;
    } formatExplain2
}
var formatResult6 = function (elCell, oRecord, oColumn, sData) {
    if (sData.length > 8) {
        elCell.innerHTML = sData.substring(0, 8) + "...";
    } else {
        elCell.innerHTML = sData;
    } formatExplain2
}
var formatExplain6 = function (elCell, oRecord, oColumn, sData) {
    if (sData.length > 8) {
        elCell.innerHTML = sData.substring(0, 8) + "...";
    } else {
        elCell.innerHTML = sData;
    } formatExplain2
}
var BindData1 = function () {
    YAHOO.example.Scrolling = function () {
        var myColumnDefs1 = [
        { key: "ID", label: "ID", resizeable: true },
        { key: "Caption", label: "姓名", resizeable: true, width: 80 },
        { key: "MobileTel", label: "手机", resizeable: true, width: 80 },
        { key: "PhraseText", label: "联系人类型", resizeable: true, width: 80 },
        { key: "Relation", label: "与决策人关系", resizeable: true, width: 80 },
        { key: "Sex", label: "性别", resizeable: true, formatter: formatSex, width: 40 },
        { key: "Position", label: "职位", resizeable: true, width: 50 },
        { key: "DeptName", label: "部门", resizeable: true, width: 50 },
        { key: "Email", label: "邮箱", resizeable: true, width: 100 },
        { key: "UName", label: "添加人", resizeable: true, width: 80 },
        { key: "AddTime", label: "添加时间", resizeable: true, width: 100 },
        { key: "AddUser", label: "添加人ID", resizeable: true }
        ];
        myDataSource1 = new YAHOO.util.DataSource([{ ID: "", Caption: "", MobileTel: "", Email: "", PhraseText: "",
            DeptName: "", Position: "", Relation: "", Sex: "", UName: "", AddTime: "", AddUser: ""
        }]);
        myDataSource1.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource1.responseSchema = {
            fields: ["ID", "Caption", "MobileTel", "Email", "PhraseText",
                        "DeptName", "Relation", "Position", "Sex", "UName", "AddTime", "AddUser"]
        };
        var myDataTable1 = new YAHOO.widget.ScrollingDataTable("con_1",
        myColumnDefs1, myDataSource1, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable1 = myDataTable1;
        var i1 = 1,
        bReverseSorted1 = false;
        var trackReverseSorts1 = function (oArg) {
            bReverseSorted1 = (oArg.dir === YAHOO.widget.ScrollingDataTable.CLASS_DESC);
        };
        myDataTable1.subscribe("rowMouseoverEvent", myDataTable1.onEventHighlightRow);
        myDataTable1.subscribe("rowMouseoutEvent", myDataTable1.onEventUnhighlightRow);
        myDataTable1.subscribe("rowClickEvent", myDataTable1.onEventSelectRow);
        myDataTable1.subscribe("rowDblclickEvent", onRowDoubleClickLinkMan);
        myDataTable1.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        GetFormValue1();
        return {
            ds: myDataSource1,
            dt: myDataTable1
        };
    } ();
}
var BindData2 = function () {
    YAHOO.example.Scrolling = function () {
        var myColumnDefs2 = [
        { key: "ID", label: "ID", resizeable: true },
        { key: "Expr1", label: "联系人", resizeable: true, width: 80 },
        { key: "PhraseText", label: "动作类型", resizeable: true, width: 60 },
        { key: "PlanStartDate", label: "开始时间", resizeable: true, width: 100 },
        { key: "PlanEndDate", label: "结束时间", resizeable: true, width: 100 },
        { key: "Contents", label: "描述", resizeable: true, formatter: formatContents2, width: 190 },
        { key: "Explain", label: "备注", resizeable: true, formatter: formatExplain2, width: 190 },
        { key: "UName", label: "添加人", resizeable: true, width: 80 },
        { key: "AddTime", label: "添加时间", resizeable: true, width: 100 }
        ];
        myDataSource2 = new YAHOO.util.DataSource([{ ID: "", Expr1: "", PhraseText: "", PlanStartDate: "", PlanEndDate: "",
            Contents: " ", Explain: "", UName: "", AddTime: ""
        }]);
        myDataSource2.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource2.responseSchema = {
            fields: ["ID", "Expr1", "PhraseText", "PlanStartDate", "PlanEndDate",
                     "Contents", "Explain", "UName", "AddTime"]
        };
        var myDataTable2 = new YAHOO.widget.ScrollingDataTable("con_2",
        myColumnDefs2, myDataSource2, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable2 = myDataTable2;
        var i2 = 1,
        bReverseSorted2 = false;
        var trackReverseSorts2 = function (oArg) {
            bReverseSorted2 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        myDataTable2.subscribe("rowMouseoverEvent", myDataTable2.onEventHighlightRow);
        myDataTable2.subscribe("rowMouseoutEvent", myDataTable2.onEventUnhighlightRow);
        myDataTable2.subscribe("rowClickEvent", myDataTable2.onEventSelectRow);
        myDataTable2.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        GetFormValue2();
        return {
            ds: myDataSource2,
            dt: myDataTable2
        };
    } ();
}
var BindData3 = function () {
    YAHOO.example.Scrolling = function () {
        var myColumnDefs3 = [
        { key: "ID", label: "ID", resizeable: true },
        { key: "Caption", label: "附件名称", resizeable: true, width: 150 },
        { key: "Size", label: "附件大小", resizeable: true, width: 80 },
        { key: "Explain", label: "说明", resizeable: true, width: 200 },
        { key: "UName", label: "添加人", resizeable: true, width: 80 },
        { key: "AddTime", label: "添加时间", resizeable: true, width: 100 },
        { key: "Address", label: "操作", resizeable: true, formatter: formatAttach, width: 200 },
        { key: "AddUser", label: "添加人ID", resizeable: true }
        ];
        myDataSource3 = new YAHOO.util.DataSource([{ ID: "", Caption: "", Size: "", Explain: "", UName: "", AddTime: "", Address: "", AddUser: ""}]);
        myDataSource3.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource3.responseSchema = {
            fields: ["ID", "Caption", "Size", "Explain", "UName", "AddTime", "Address", "AddUser"]
        };
        var myDataTable3 = new YAHOO.widget.ScrollingDataTable("con_3",
        myColumnDefs3, myDataSource3, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable3 = myDataTable3;
        var i3 = 1,
        bReverseSorted3 = false;
        var trackReverseSorts3 = function (oArg) {
            bReverseSorted3 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        myDataTable3.subscribe("rowMouseoverEvent", myDataTable3.onEventHighlightRow);
        myDataTable3.subscribe("rowMouseoutEvent", myDataTable3.onEventUnhighlightRow);
        myDataTable3.subscribe("rowClickEvent", myDataTable3.onEventSelectRow);
        myDataTable3.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        GetFormValue3();
        return {
            ds: myDataSource3,
            dt: myDataTable3
        };
    } ();
}
var BindData4 = function () {
    YAHOO.example.Scrolling = function () {
        var myColumnDefs4 = [
        { key: "ID", label: "订单ID", resizeable: true },
        { key: "TypeID", label: "订单类型ID", resizeable: true },
        { key: "Code", label: "订单编码", resizeable: true, width: 80 },
        { key: "OrderDeptName", label: "业绩归属", resizeable: true, width: 80 },
        { key: "OrderTypeName", label: "订单类型", resizeable: true, width: 80 },
        { key: "OrderStateName", label: "订单状态", resizeable: true, width: 80 },
        { key: "ResignMoney", label: "已收金额", resizeable: true, width: 100 },
        { key: "TotalMoney", label: "总金额", resizeable: true, width: 100 },
        { key: "PaymentType", label: "付款方式", resizeable: true, width: 80 },
        { key: "OrderAddUName", label: "填单人", resizeable: true, width: 80 },
        { key: "AddTime", label: "订单日期", resizeable: true, width: 100 }
        ];
        myDataSource4 = new YAHOO.util.DataSource([{ ID: "", TypeID: "", Code: "", OrderDeptName: "",
            OrderTypeName: "", OrderStateName: "", ResignMoney: "", TotalMoney: "", PaymentType: "",
            OrderAddUName: "", AddTime: ""
        }]);
        myDataSource4.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource4.responseSchema = {
            fields: ["ID", "TypeID", "Code", "OrderDeptName", "OrderTypeName",
                        "OrderStateName", "ResignMoney", "TotalMoney", "PaymentType", "OrderAddUName", "AddTime"]
        };
        var myDataTable4 = new YAHOO.widget.ScrollingDataTable("con_4",
        myColumnDefs4, myDataSource4, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable4 = myDataTable4;
        var i4 = 1,
        bReverseSorted4 = false;
        var trackReverseSorts4 = function (oArg) {
            bReverseSorted4 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        myDataTable4.subscribe("rowMouseoverEvent", myDataTable4.onEventHighlightRow);
        myDataTable4.subscribe("rowMouseoutEvent", myDataTable4.onEventUnhighlightRow);
        myDataTable4.subscribe("rowClickEvent", myDataTable4.onEventSelectRow);
        myDataTable4.subscribe("rowDblclickEvent", onRowDoubleClickOrder);
        myDataTable4.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        GetFormValue4();
        return {
            ds: myDataSource4,
            dt: myDataTable4
        };
    } ();
}
var BindData5 = function () {
    YAHOO.example.Scrolling = function () {
        var myColumnDefs5 = [
        { key: "ID", label: "ID", resizeable: true },
        { key: "CustomerName", label: "客户名称", resizeable: true, width: 230 },
        { key: "Code", label: "缴款单号", resizeable: true, width: 80 },
        { key: "Date", label: "缴款日期", resizeable: true, width: 100 },
        { key: "StateName", label: "状态", resizeable: true, width: 80 },
        { key: "DeptName", label: "业绩归属", resizeable: true, width: 80 },
        { key: "UName", label: "填单人", resizeable: true, width: 80 }
        ];
        myDataSource5 = new YAHOO.util.DataSource([{ ID: "", CustomerName: "", Code: "", Date: "",
            StateName: "", DeptName: "", UName: ""
        }]);
        myDataSource5.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource5.responseSchema = {
            fields: ["ID", "CustomerName", "Code", "Date",
            "StateName", "DeptName", "UName"]
        };
        var myDataTable5 = new YAHOO.widget.ScrollingDataTable("con_5",
        myColumnDefs5, myDataSource5, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable5 = myDataTable5;
        var i5 = 1,
        bReverseSorted5 = false;
        var trackReverseSorts5 = function (oArg) {
            bReverseSorted5 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        myDataTable5.subscribe("rowMouseoverEvent", myDataTable5.onEventHighlightRow);
        myDataTable5.subscribe("rowMouseoutEvent", myDataTable5.onEventUnhighlightRow);
        myDataTable5.subscribe("rowClickEvent", myDataTable5.onEventSelectRow);
        myDataTable5.subscribe("rowDblclickEvent", onRowDoubleClickPay);
        myDataTable5.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        GetFormValue5();
        return {
            ds: myDataSource5,
            dt: myDataTable5
        };
    } ();
}
var BindData6 = function () {
    YAHOO.example.Scrolling = function () {
        var myColumnDefs6 = [
        { key: "ID", label: "ID", resizeable: true },
        { key: "Expr1", label: "联系人", resizeable: true, width: 80 },
        { key: "PhraseText", label: "动作类型", resizeable: true, width: 80 },
        { key: "PlanStartDate", label: "开始时间", resizeable: true, width: 100 },
        { key: "PlanEndDate", label: "结束时间", resizeable: true, width: 100 },
        { key: "AnticipeResult", label: "预期结果", resizeable: true, formatter: formatAnticipeResult6, width: 200 },
        { key: "Contents", label: "过程描述", resizeable: true, formatter: formatContents6, width: 200 },
        { key: "Result", label: "完成情况", resizeable: true, formatter: formatResult6, width: 200 },
        { key: "Explain", label: "备注", resizeable: true, formatter: formatExplain6, width: 200 },
        { key: "UName", label: "添加人", resizeable: true, width: 80 },
        { key: "AddTime", label: "添加时间", resizeable: true, width: 100 },
        { key: "AddUser", label: "添加人ID", resizeable: true }
        ];
        myDataSource6 = new YAHOO.util.DataSource([{ ID: "", Expr1: "", PhraseText: "", PlanStartDate: "", PlanEndDate: "",
            AnticipeResult: "", Contents: " ", Result: "", Explain: "", UName: "", AddTime: "", AddUser: ""
        }]);
        myDataSource6.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource6.responseSchema = {
            fields: ["ID", "Expr1", "PhraseText", "PlanStartDate", "PlanEndDate", "AnticipeResult",
                     "Contents", "Result", "Explain", "UName", "AddTime", "AddUser"]
        };
        var myDataTable6 = new YAHOO.widget.ScrollingDataTable("con_6",
        myColumnDefs6, myDataSource6, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable6 = myDataTable6;
        var i6 = 1,
        bReverseSorted6 = false;
        var trackReverseSorts6 = function (oArg) {
            bReverseSorted6 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        myDataTable6.subscribe("rowMouseoverEvent", myDataTable6.onEventHighlightRow);
        myDataTable6.subscribe("rowMouseoutEvent", myDataTable6.onEventUnhighlightRow);
        myDataTable6.subscribe("rowClickEvent", myDataTable6.onEventSelectRow);
        myDataTable6.subscribe("rowDblclickEvent", onRowDoubleClickActivity);
        myDataTable6.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        GetFormValue6();
        return {
            ds: myDataSource6,
            dt: myDataTable6
        };
    } ();
}
var BindData7 = function () {
    YAHOO.example.Scrolling = function () {
        var myColumnDefs7 = [
        { key: "ThodometerId", label: "ThodometerId", resizeable: true },
        { key: "CustomerName", label: "客户名称", resizeable: true, width: 230 },
        { key: "LectorName", label: "讲师名称", resizeable: true, width: 80 },
        { key: "PrelectDate", label: "讲课时间", resizeable: true, width: 100 },
        { key: "TeachPlace", label: "讲课地点", resizeable: true, width: 80 },
        { key: "BargainNum", label: "成交家数", resizeable: true, width: 80 },
        { key: "DeptName", label: "所属分公司", resizeable: true, width: 80 },
        { key: "AddTeachSumpName", label: "添加人", resizeable: true, width: 80 },
        { key: "Addtime", label: "添加时间", resizeable: true, width: 100 }
        ];
        myDataSource7 = new YAHOO.util.DataSource([{ ThodometerId: "", CustomerName: "", LectorName: "", PrelectDate: "",
            TeachPlace: "", BargainNum: " ", DeptName: "", AddTeachSumpName: "", Addtime: ""
        }]);
        myDataSource7.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource7.responseSchema = {
            fields: ["ThodometerId", "CustomerName", "LectorName", "PrelectDate", "TeachPlace",
                     "BargainNum", "DeptName", "AddTeachSumpName", "Addtime"]
        };
        var myDataTable7 = new YAHOO.widget.ScrollingDataTable("con_7",
        myColumnDefs7, myDataSource7, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable7 = myDataTable7;
        var i7 = 1,
        bReverseSorted7 = false;
        var trackReverseSorts7 = function (oArg) {
            bReverseSorted7 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        myDataTable7.subscribe("rowMouseoverEvent", myDataTable7.onEventHighlightRow);
        myDataTable7.subscribe("rowMouseoutEvent", myDataTable7.onEventUnhighlightRow);
        myDataTable7.subscribe("rowClickEvent", myDataTable7.onEventSelectRow);
        myDataTable7.subscribe("rowDblclickEvent", onRowDoubleClickTeachSump);
        myDataTable7.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        GetFormValue7();
        return {
            ds: myDataSource7,
            dt: myDataTable7
        };
    } ();
}
var BindData8 = function () {
    YAHOO.example.Scrolling = function () {
        var myColumnDefs8 = [
        { key: "ID", label: "ID", resizeable: true },
        { key: "Code", label: "客户编码", resizeable: true, width: 80 },
        { key: "CustomerName", label: "客户名称", resizeable: true, width: 230 },
        { key: "AddUserName", label: "分配人", resizeable: true, width: 80 },
        { key: "ToUserName", label: "被分配人", resizeable: true, width: 80 },
        { key: "AddTime", label: "分配时间", resizeable: true, width: 100 }
        ];
        myDataSource8 = new YAHOO.util.DataSource([{ ID: "", Code: "", CustomerName: " ", AddUserName: "", ToUserName: "", AddTime: ""
        }]);
        myDataSource8.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource8.responseSchema = {
            fields: ["ID", "Code", "CustomerName", "AddUserName", "ToUserName", "AddTime"]
        };
        var myDataTable8 = new YAHOO.widget.ScrollingDataTable("con_8",
        myColumnDefs8, myDataSource8, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable8 = myDataTable8;
        var i8 = 1,
        bReverseSorted8 = false;
        var trackReverseSorts8 = function (oArg) {
            bReverseSorted8 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        myDataTable8.subscribe("rowMouseoverEvent", myDataTable8.onEventHighlightRow);
        myDataTable8.subscribe("rowMouseoutEvent", myDataTable8.onEventUnhighlightRow);
        myDataTable8.subscribe("rowClickEvent", myDataTable8.onEventSelectRow);
        myDataTable8.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        GetFormValue8();
        return {
            ds: myDataSource8,
            dt: myDataTable8
        };
    } ();
}
var BindData9 = function () {
    YAHOO.example.Scrolling = function () {
        var myColumnDefs9 = [
        { key: "ID", label: "ID", resizeable: true },
        { key: "Code", label: "客户编码", resizeable: true, width: 80 },
        { key: "CustomerName", label: "客户名称", resizeable: true, width: 230 },
        { key: "RelationCustomerName", label: "关系客户名称", resizeable: true, width: 230 },
        { key: "PhraseText", label: "所属关系", resizeable: true, width: 80 },
        { key: "UName", label: "添加人", resizeable: true, width: 80 },
        { key: "AddTime", label: "添加时间", resizeable: true, width: 100 },
        { key: "AddUser", label: "添加人ID", resizeable: true }
        ];
        myDataSource9 = new YAHOO.util.DataSource([{ ID: "", Code: "", CustomerName: " ", RelationCustomerName: "",
            PhraseText: "", UName: "", AddTime: "", AddUser: ""
        }]);
        myDataSource9.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource9.responseSchema = {
            fields: ["ID", "Code", "CustomerName", "RelationCustomerName", "PhraseText",
                "UName", "AddTime", "AddUser"]
        };
        var myDataTable9 = new YAHOO.widget.ScrollingDataTable("con_9",
        myColumnDefs9, myDataSource9, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable9 = myDataTable9;
        var i9 = 1,
        bReverseSorted9 = false;
        var trackReverseSorts9 = function (oArg) {
            bReverseSorted9 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        myDataTable9.subscribe("rowMouseoverEvent", myDataTable9.onEventHighlightRow);
        myDataTable9.subscribe("rowMouseoutEvent", myDataTable9.onEventUnhighlightRow);
        myDataTable9.subscribe("rowClickEvent", myDataTable9.onEventSelectRow);
        myDataTable9.subscribe("rowDblclickEvent", onRowDoubleClickCustomerRelation);
        myDataTable9.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        GetFormValue9();
        return {
            ds: myDataSource9,
            dt: myDataTable9
        };
    } ();
}
var BindData10 = function () {
    YAHOO.example.Scrolling = function () {
        var myColumnDefs10 = [
        { key: "WorkFlowInsId", label: "WorkFlowInsId", resizeable: true },
        { key: "CustomerCode", label: "客户编码", resizeable: true, width: 80 },
        { key: "CustomerName", label: "客户名称", resizeable: true, width: 230 },
        { key: "Code", label: "公开课单号", resizeable: true, width: 80 },
        { key: "CourseLayoutName", label: "课程期数", resizeable: true, width: 230 },
        { key: "Amount", label: "成交数量", resizeable: true, width: 40 },
        { key: "ServerName", label: "课中服务人", resizeable: true, width: 80 },
        { key: "FrontServerName", label: "负责交付人", resizeable: true, width: 80 },
        { key: "TeacherName", label: "谈单老师", resizeable: true, width: 100 },
        { key: "exp3", label: "现场完款", resizeable: true, width: 40 },
        { key: "DeliverStateName", label: "状态", resizeable: true, width: 40 },
        { key: "AddUserName", label: "添加人", resizeable: true, width: 80 },
        { key: "AddTime", label: "添加时间", resizeable: true, width: 100 }
        ];
        myDataSource10 = new YAHOO.util.DataSource([{ WorkFlowInsId: "", CustomerCode: "", CustomerName: "",
            Code: "", CourseLayoutName: "", Amount: "", ServerName: "", FrontServerName: "",
            TeacherName: "", exp3: "", DeliverStateName: "", AddUserName: "", AddTime: ""
        }]);
        myDataSource10.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource10.responseSchema = {
            fields: ["WorkFlowInsId", "CustomerCode", "CustomerName", "Code", "CourseLayoutName", "Amount", "ServerName",
                "FrontServerName", "TeacherName", "exp3", "DeliverStateName", "AddUserName", "AddTime"]
        };
        var myDataTable10 = new YAHOO.widget.ScrollingDataTable("con_10",
        myColumnDefs10, myDataSource10, { width: "99.8%", height:"100%", selectionMode: "single" });
        mDataTable10 = myDataTable10;
        var i10 = 1,
        bReverseSorted10 = false;
        var trackReverseSorts10 = function (oArg) {
            bReverseSorted10 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        myDataTable10.subscribe("rowMouseoverEvent", myDataTable10.onEventHighlightRow);
        myDataTable10.subscribe("rowMouseoutEvent", myDataTable10.onEventUnhighlightRow);
        myDataTable10.subscribe("rowClickEvent", myDataTable10.onEventSelectRow);
        myDataTable10.subscribe("rowDblclickEvent", onRowDoubleClickDeliverMajor);
        myDataTable10.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        LoadDeliverMajor();
        return {
            ds: myDataSource10,
            dt: myDataTable10
        };
    } ();
}
var BindData11 = function () {
    YAHOO.example.Scrolling = function () {
        var myColumnDefs11 = [
        { key: "WorkFlowInsId", label: "WorkFlowInsId", resizeable: true },
        { key: "Code", label: "内训单号", resizeable: true, width: 80 },
        { key: "IsSingleTrain", label: "独立内训", resizeable: true, width: 40 },
        { key: "TrainSum", label: "内训天数", resizeable: true, width: 40 },
        { key: "BeginDate", label: "启动时间", resizeable: true, width: 100 },
        { key: "EndDate", label: "结案时间", resizeable: true, width: 100 },
        { key: "PhraseText", label: "状态", resizeable: true, width: 40 },
        { key: "UName", label: "添加人", resizeable: true, width: 80 },
        { key: "AddTime", label: "添加时间", resizeable: true, width: 100 }
        ];
        myDataSource11 = new YAHOO.util.DataSource([{ WorkFlowInsId: "", Code: "", IsSingleTrain: "",
            TrainSum: "", BeginDate: "", EndDate: "", PhraseText: "", UName: "", AddTime: ""
        }]);
        myDataSource11.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource11.responseSchema = {
            fields: ["WorkFlowInsId", "Code", "IsSingleTrain", "TrainSum", "BeginDate",
            "EndDate", "PhraseText", "UName", "AddTime"]
        };
        var myDataTable11 = new YAHOO.widget.ScrollingDataTable("con_11",
        myColumnDefs11, myDataSource11, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable11 = myDataTable11;
        var i11 = 1,
        bReverseSorted11 = false;
        var trackReverseSorts11 = function (oArg) {
            bReverseSorted11 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        myDataTable11.subscribe("rowMouseoverEvent", myDataTable11.onEventHighlightRow);
        myDataTable11.subscribe("rowMouseoutEvent", myDataTable11.onEventUnhighlightRow);
        myDataTable11.subscribe("rowClickEvent", myDataTable11.onEventSelectRow);
        myDataTable11.subscribe("rowDblclickEvent", onRowDoubleClickDeliverTrain);
        myDataTable11.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        LoadDeliverTrain();
        return {
            ds: myDataSource11,
            dt: myDataTable11
        };
    } ();
}
var BindData12 = function () {
    YAHOO.example.Scrolling = function () {
        var myColumnDefs12 = [
        { key: "WorkFlowInsId", label: "WorkFlowInsId", resizeable: true },
        { key: "Code", label: "项目单号", resizeable: true, width: 80 },
        { key: "ProductName", label: "产品名称", resizeable: true, width: 100 },
        { key: "FzjfName", label: "交付负责人", resizeable: true, width: 80 },
        { key: "PhraseText", label: "状态", resizeable: true, width: 40 },
        { key: "UName", label: "添加人", resizeable: true, width: 80 },
        { key: "AddTime", label: "添加时间", resizeable: true, width: 100 }
        ];
        myDataSource12 = new YAHOO.util.DataSource([{ WorkFlowInsId: "", Code: "", ProductName: "",
            FzjfName: "", PhraseText: "", UName: "", AddTime: ""
        }]);
        myDataSource12.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource12.responseSchema = {
            fields: ["WorkFlowInsId", "Code", "ProductName", "FzjfName", "PhraseText", "UName", "AddTime"]
        };
        var myDataTable12 = new YAHOO.widget.ScrollingDataTable("con_12",
        myColumnDefs12, myDataSource12, { width: "99.8%", height: "100%", selectionMode: "single" });
        mDataTable12 = myDataTable12;
        var i12 = 1,
        bReverseSorted12 = false;
        var trackReverseSorts12 = function (oArg) {
            bReverseSorted12 = (oArg.dir === YAHOO.widget.DataTable.CLASS_DESC);
        };
        myDataTable12.subscribe("rowMouseoverEvent", myDataTable12.onEventHighlightRow);
        myDataTable12.subscribe("rowMouseoutEvent", myDataTable12.onEventUnhighlightRow);
        myDataTable12.subscribe("rowClickEvent", myDataTable12.onEventSelectRow);
        myDataTable12.subscribe("rowDblclickEvent", onRowDoubleClickDeliverProInfo);
        myDataTable12.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        LoadDeliverProInfo();
        return {
            ds: myDataSource12,
            dt: myDataTable12
        };
    } ();
}
var hideCol = function () {
    mDataTable1.hideColumn(parseInt(0)); mDataTable1.refreshView();
    mDataTable1.hideColumn(parseInt(11)); mDataTable1.refreshView();
    mDataTable2.hideColumn(parseInt(0)); mDataTable2.refreshView();
    mDataTable3.hideColumn(parseInt(0)); mDataTable3.refreshView();
    mDataTable3.hideColumn(parseInt(7)); mDataTable3.refreshView();
    mDataTable4.hideColumn(parseInt(0)); mDataTable4.refreshView();
    mDataTable4.hideColumn(parseInt(1)); mDataTable4.refreshView();
    mDataTable5.hideColumn(parseInt(0)); mDataTable5.refreshView();
    mDataTable6.hideColumn(parseInt(0)); mDataTable6.refreshView();
    mDataTable6.hideColumn(parseInt(11)); mDataTable6.refreshView();
    mDataTable7.hideColumn(parseInt(0)); mDataTable7.refreshView();
    mDataTable8.hideColumn(parseInt(0)); mDataTable8.refreshView();
    mDataTable9.hideColumn(parseInt(0)); mDataTable9.refreshView();
    mDataTable9.hideColumn(parseInt(7)); mDataTable9.refreshView();
    mDataTable10.hideColumn(parseInt(0)); mDataTable10.refreshView();
    mDataTable11.hideColumn(parseInt(0)); mDataTable11.refreshView();
    mDataTable12.hideColumn(parseInt(0)); mDataTable12.refreshView();
}

//联系人
var GetFormValue1 = function () {
    for (var i = 0; i < vLinkMan.length; i++) {
        SetFormValue1(vLinkMan);
    }
}
var SetFormValue1 = function (obj) {
    var arr = eval(obj);
    myDataSource1.liveData = arr;
    mDataTable1.getDataSource().sendRequest(null, { success: mDataTable1.onDataReturnInitializeTable }, mDataTable1);
}
//行销中心记录
var GetFormValue2 = function () {
    for (var i = 0; i < vLinkRecord.length; i++) {
        SetFormValue2(vLinkRecord);
    }
}
var SetFormValue2 = function (obj) {
    var arr = eval(obj);
    myDataSource2.liveData = arr;
    mDataTable2.getDataSource().sendRequest(null, { success: mDataTable2.onDataReturnInitializeTable }, mDataTable2);
}
//附件
var GetFormValue3 = function () {
    for (var i = 0; i < vAttach.length; i++) {
        SetFormValue3(vAttach);
    }
}
var SetFormValue3 = function (obj) {
    var arr = eval(obj);
    myDataSource3.liveData = arr;
    mDataTable3.getDataSource().sendRequest(null, { success: mDataTable3.onDataReturnInitializeTable }, mDataTable3);
}
//商机任务记录
var GetFormValue6 = function () {
    for (var i = 0; i < vLinkChoice.length; i++) {
        SetFormValue6(vLinkChoice);
    }
}
var SetFormValue6 = function (obj) {
    var arr = eval(obj);
    myDataSource6.liveData = arr;
    mDataTable6.getDataSource().sendRequest(null, { success: mDataTable6.onDataReturnInitializeTable }, mDataTable6);
}
//订单
var GetFormValue4 = function () {
    for (var i = 0; i < vOrder.length; i++) {
        SetFormValue4(vOrder);
    }
}
var SetFormValue4 = function (obj) {
    var arr = eval(obj);
    myDataSource4.liveData = arr;
    mDataTable4.getDataSource().sendRequest(null, { success: mDataTable4.onDataReturnInitializeTable }, mDataTable4);
}
//缴款单
var GetFormValue5 = function () {
    for (var i = 0; i < vPay.length; i++) {
        SetFormValue5(vPay);
    }
}
var SetFormValue5 = function (obj) {
    var arr = eval(obj);
    myDataSource5.liveData = arr;
    mDataTable5.getDataSource().sendRequest(null, { success: mDataTable5.onDataReturnInitializeTable }, mDataTable5);
}
//讲师总结
var GetFormValue7 = function () {
    for (var i = 0; i < vTeachSump.length; i++) {
        SetFormValue7(vTeachSump);
    }
}
var SetFormValue7 = function (obj) {
    var arr = eval(obj);
    myDataSource7.liveData = arr;
    mDataTable7.getDataSource().sendRequest(null, { success: mDataTable7.onDataReturnInitializeTable }, mDataTable7);
}
//客户分配记录
var GetFormValue8 = function () {
    for (var i = 0; i < vFPRecord.length; i++) {
        SetFormValue8(vFPRecord);
    }
}
var SetFormValue8 = function (obj) {
    var arr = eval(obj);
    myDataSource8.liveData = arr;
    mDataTable8.getDataSource().sendRequest(null, { success: mDataTable8.onDataReturnInitializeTable }, mDataTable8);
}
//客户关系列表
var GetFormValue9 = function () {
    for (var i = 0; i < vGXList.length; i++) {
        SetFormValue9(vGXList);
    }
}
var SetFormValue9 = function (obj) {
    var arr = eval(obj);
    myDataSource9.liveData = arr;
    mDataTable9.getDataSource().sendRequest(null, { success: mDataTable9.onDataReturnInitializeTable }, mDataTable9);
}
//公开课交付单列表
var SetFormValue10 = function (obj) {
    var arr = eval(obj);
    myDataSource10.liveData = arr;
    mDataTable10.getDataSource().sendRequest(null, { success: mDataTable10.onDataReturnInitializeTable }, mDataTable10);
}
//内训交付单列表
var SetFormValue11 = function (obj) {
    var arr = eval(obj);
    myDataSource11.liveData = arr;
    mDataTable11.getDataSource().sendRequest(null, { success: mDataTable11.onDataReturnInitializeTable }, mDataTable11);
}
//项目交付单列表
var SetFormValue12 = function (obj) {
    var arr = eval(obj);
    myDataSource12.liveData = arr;
    mDataTable12.getDataSource().sendRequest(null, { success: mDataTable12.onDataReturnInitializeTable }, mDataTable12);
}





//检查客户名是否已存在
function CheckCustomerName() {
    var vName = $('#CustomerName').val();
    if (vName != "") {
        YAHOO.util.Connect.asyncRequest('POST', Url + "?r=" + Math.random() + "&id=" + vid + "&temp=" + flag + "&entity=CustomerName&action=check&name=" + encodeURI(vName) + "", //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
                if (str == "0") {  //失败
                    $('#CustomerName').focus();
                    document.getElementById("CustomerName").value = "";
                    return;
                } else if (str == "1") {   //客户名称已经存在
                    //alert("该客户名称已经存在!");
                    SetMaxDWH(YAHOO.example.container.dialog1, 23, 200);
                    document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerShow&order=Code&ct=0&cn=" + encodeURI(vName);
                    YAHOO.example.container.dialog1.show();
                    document.getElementById("yui-gen0-button").style.display = "none";
                    $('#CustomerName').focus();
                    document.getElementById("CustomerName").value = "";
                    return;
                } else if (str == "11") {
                    //alert("该客户名称已经存在!");
                    SetMaxDWH(YAHOO.example.container.dialog1, 23, 200);
                    document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerInfoSale&order=Code&ct=0&cn=" + encodeURI(vName);
                    YAHOO.example.container.dialog1.show();
                    document.getElementById("yui-gen0-button").style.display = "none";
                    $('#CustomerName').focus();
                    document.getElementById("CustomerName").value = "";
                    return;
                } else if (str == "111") {  //客户名长度大8
                    saveState = 1;
                    var name = vName.substring(4, 8);
                    SetMaxDWH(YAHOO.example.container.dialog4, 23, 200);
                    document.getElementById("EditUIWindow4").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerShow&order=Code&ct=2&cn=" + encodeURI(name);
                    YAHOO.example.container.dialog4.show();
                    $('#CustomerName').focus();
                    return false;
                } else if (str == "1111") {  //客户名长度大于8
                    if (saveState == 1) {
                        trySave();
                    } else {
                        saveState = 1;
                        var name = vName.substring(4, 8);
                        SetMaxDWH(YAHOO.example.container.dialog4, 23, 200);
                        document.getElementById("EditUIWindow4").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerInfoSale&order=Code&ct=2&cn=" + encodeURI(name);
                        YAHOO.example.container.dialog4.show();
                        $('#CustomerName').focus();
                        return false;
                    }
                } else if (str == "2") {
                    alert("该客户名可以使用!");
                    $('#State').focus();
                    return;
                }
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
    });
    } else {
        alert("客户名不能为空!");
        $('#CustomerName').focus();
    }
}
//检查决策人手机是否已存在
function CheckDecisionTel() {
    var vDecisionTel = $('#DecisionTel').val();
    var vValue = vDecisionTel;
    if (vValue != "") {
        YAHOO.util.Connect.asyncRequest('POST', Url + "?r=" + Math.random() + "&id=" + vid + "&temp=" + flag + "&entity=CustomerTel&action=check&name=" + encodeURI(vValue) + "", //条件 
            {success: function (res) {
                try {
                    var str = res.responseText;
                    if (str == "0") {  //失败
                        $('#DecisionTel').focus();
                        document.getElementById("DecisionTel").value = "";
                        return;
                    } else if (str == "1") {   //决策人手机已经存在
                        //alert("该决策人手机已经存在!");
                        SetMaxDWH(YAHOO.example.container.dialog1, 23, 200);
                        document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerShow&order=Code&ct=1&cn=" + encodeURI(vValue);
                        YAHOO.example.container.dialog1.show();
                        document.getElementById("yui-gen0-button").style.display = "none";
                        $('#DecisionTel').focus();
                        document.getElementById("DecisionTel").value = "";
                        return;
                    } else if (str == "11") {
                        //alert("该决策人手机已经存在!");
                        SetMaxDWH(YAHOO.example.container.dialog1, 23, 200);
                        document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerInfoSale&order=Code&ct=1&cn=" + encodeURI(vValue);
                        YAHOO.example.container.dialog1.show();
                        document.getElementById("yui-gen0-button").style.display = "none";
                        $('#DecisionTel').focus();
                        document.getElementById("DecisionTel").value = "";
                        return;
                    } else if (str == "2") {
                        alert("该决策人手机可以使用!");
                        $('#DecisionPosition').focus();
                        return;
                    }
                }
                catch (e) {
                }
                finally {
                }
            }, failure: function () { }
        });
    } else {
        alert("决策人手机不能为空!");
        $('#DecisionTel').focus();
    }
}
//查看状态设置
function GetCheckState() {
    if (flag == "1" || flag == "3") {
        $("#btnSave").attr('disabled', "true");
    }
    $('#btnCheckCustomerName').hide(); //隐藏按钮
    $('#btnDecisionTel').hide(); //隐藏按钮
    $('#btnAddUserName').hide(); //隐藏按钮
    $('#btnSaleadviserId').hide(); //隐藏按钮
    $('#btnLectorName').hide(); //隐藏按钮
    $('#btnCustomeerMgrs').hide(); //隐藏按钮
    $("#Lectortime").attr("disabled", "true");
    var obj = document.getElementById("fieldForm"); //得到DIV对象
    var e = obj.getElementsByTagName("input"); //得到此DIV里的所有INPUT对象
    var s = obj.getElementsByTagName("select");
    var t = obj.getElementsByTagName("textarea");
    for (var i = 0; i < e.length; i++) {
        //e[i].disabled = true;
        $("#" + e[i].id + "").attr("readonly", "readonly");
    }
    for (var j = 0; j < s.length; j++) {
        s[j].disabled = true;
    }
    for (var k = 0; k < t.length; k++) {
        //t[k].disabled = true;
        $("#" + t[k].id + "").attr("readonly", "readonly");
    }
}


//保存
function setValue() {
    instance[0].ID = $('#ID').val().replace(/(^\s*)|(\s*$)/g, '');
    instance[0].Code = $('#Code').val().replace(/(^\s*)|(\s*$)/g, '');
    instance[0].CustomerName = $('#CustomerName').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].Address = $('#Address').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].State = $("#State").find("option:selected").text();
    instance[0].Province = $("#Province").find("option:selected").text();
    instance[0].City = $("#City").find("option:selected").text();
    instance[0].Area = $("#Area").find("option:selected").text();
    instance[0].CompanyProduct = $('#CompanyProduct').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionAttitude = $('#DecisionAttitude').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, ""); //培训态度
    instance[0].Tel1 = $('#Tel1').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].Tel2 = $('#Tel2').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].Post = $('#Post').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].CompanyAttention = $('#CompanyAttention').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].CusTestimony = $('#CusTestimony').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].Fax = $('#Fax').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].Decisionmaker = $('#Decisionmaker').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionSex = $('#DecisionSex').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionTel = $('#DecisionTel').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].Character = $('#Character').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionPosition = $('#DecisionPosition').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionBirthday = $('#DecisionBirthday').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].BirthdayType = $('#BirthdayType').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].Homeplace = $('#Homeplace').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].SchoolScientifc = $('#SchoolScientifc').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionEmail = $('#DecisionEmail').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionFancy = $('#DecisionFancy').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionTick = $('#DecisionTick').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].Credit = $('#Credit').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionLearn = $('#DecisionLearn').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionRest = $('#DecisionRest').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionType = $('#DecisionType').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionFeelType = $('#DecisionFeelType').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionBuyType = $('#DecisionBuyType').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].PersonId = $('#PersonId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].AreaId = $('#AreaId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].TypeId = $('#TypeId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].LevelId = $('#LevelId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].TradeId = $('#TradeId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].ProductId = $('#ProductId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].OriginId = $("#OriginId").val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].PropertyId = $('#PropertyId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].UnionId = $('#UnionId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");  //商会
    instance[0].MnemonicCode = $('#MnemonicCode').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].CompanyNetting = $('#CompanyNetting').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].Email = $('#Email').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].CustomerSaleTyte = $('#CustomerSaleTyte').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].CompeterCustomer = $('#CompeterCustomer').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].IsTrainDept = $('#IsTrainDept').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].CustomerDream = $('#CustomerDream').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].DecisionPersonsun = $('#DecisionPersonsun').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].HighPersonsum = $('#HighPersonsum').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].MiddlePersonsum = $('#MiddlePersonsum').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].BelowPersonsum = $('#BelowPersonsum').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].TrainCompany = $('#TrainCompany').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].TrainDate = $('#TrainDate').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].CustomerPromis = $('#CustomerPromis').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].AffectDecisioner = $('#AffectDecisioner').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].TrainHistory = $('#TrainHistory').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].Painful = $('#Painful').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].Pullulation = $('#Pullulation').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].CustomerPhylogeny = $('#CustomerPhylogeny').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].PersonSum = $('#PersonSum').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].PersonSum2 = $('#PersonSum2').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].PersonSum3 = $('#PersonSum3').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].TradeDegree = $('#TradeDegree').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].PayOffNum1 = $('#PayOffNum1').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].PayOffNum2 = $('#PayOffNum2').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].PayOffNum3 = $('#PayOffNum3').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].ProductSum = $('#ProductSum').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].ProductSum2 = $('#ProductSum2').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].ProductSum3 = $('#ProductSum3').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].CompanyGain = $('#CompanyGain').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].ProfitNum1 = $('#ProfitNum1').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].ProfitNum2 = $('#ProfitNum2').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].ProfitNum3 = $('#ProfitNum3').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].CusTrainbudget = $('#CusTrainbudget').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].ManagerQuestion = $('#ManagerQuestion').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].StrongPoint = $('#StrongPoint').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].Explain = $('#Explain').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
    instance[0].IsHistory = "0";
    instance[0].IsPrevate = "1";
    instance[0].IsValue = "1";
    instance[0].AddUser = $("#hiddenAddUser").val();
    instance[0].AddTime = $("#AddTime").val();
    instance[0].exp1 = $("#exp1").val(); //企业成立日期(年)
    instance[0].exp2 = $("#exp2").val(); //企业成立日期(月)
    instance[0].exp3 = $("#exp3").val(); //企业成立日期(日)
    
    instance[0].CustomeerMgr = $("#CustomeerMgrs").val(); //客户经理
    if (flag=="2" || flag == "3" || flag == "4") {
        instance[0].AddUser = $("#AddUserName").val(); //信息专员
        instance[0].SaleadviserId = $("#SaleadviserId").val(); //行销顾问
        instance[0].LectorUser = $("#LectorName").val(); //推广讲师
        instance[0].Lectortime = $("#Lectortime").val(); //讲场时间
    }
}
var Save = function () {
    setValue();
    if (flag == "3") {
        if (instance[0].CustomeerMgr == "" || instance[0].CustomeerMgr == null) {
            alert("客户经理不能为空!");
            $('#txtCustomeerMgrs').focus();
            return;
        }
    }
    if (instance[0].CustomerName == "") {
        alert("客户名称不能为空!");
        $('#CustomerName').focus();
        return;
    }
    if (instance[0].Province == "" || instance[0].Province == "选择省份") {
        alert("省份不能为空!");
        $('#Province').focus();
        return;
    }
    if (instance[0].City == "" || instance[0].City == "选择城市") {
        alert("城市不能为空!");
        $('#City').focus();
        return;
    }
    if (instance[0].Address == "") {
        alert("地址不能为空!");
        $('#Address').focus();
        return;
    }
    if (instance[0].CompanyProduct == "") {
        alert("主营业务不能为空!");
        $('#CompanyProduct').focus();
        return;
    }
    if (instance[0].DecisionAttitude == "") {
        alert("培训态度不能为空!");
        $('#DecisionAttitude').focus();
        return;
    }
    if (instance[0].Tel1 == "") {
        alert("公司电话1不能为空!");
        $('#Tel1').focus();
        return;
    }
    if (instance[0].Decisionmaker == "") {
        alert("决策人姓名不能为空!");
        $('#Decisionmaker').focus();
        return;
    }
    if (instance[0].Decisionmaker.length < 2) {
        alert("决策人姓名不能为单个汉字!");
        $('#Decisionmaker').focus();
        return;
    }
    if (instance[0].DecisionSex == "" || instance[0].DecisionSex == null) {
        alert("决策人性别不能为空!");
        $('#DecisionSex').focus();
        return;
    }
    if (instance[0].DecisionTel == "") {
        alert("决策人手机不能为空!");
        $('#DecisionTel').focus();
        return;
    }
    /*if (instance[0].Character == "") {
        alert("决策人性格不能为空!");
        $('#Character').focus();
        return;
    }*/
    if (instance[0].DecisionPosition == "") {
        alert("决策人职务不能为空!");
        $('#DecisionPosition').focus();
        return;
    }
    if (instance[0].DecisionBirthday == "") {
        instance[0].DecisionBirthday = "1900-01-01";
        //alert("决策人生日日期不能为空!");
        //$('#DecisionBirthday').focus();
        //return;
    }
    if (instance[0].CompanyCreateDate == "") {
        alert("企业成立日期不能为空!");
        $('#CompanyCreateDate').focus();
        return;
    }
    if (instance[0].PersonId == "" || instance[0].PersonId == null) {
        alert("员工人数不能为空!");
        $('#PersonId').focus();
        return;
    }
    if (instance[0].TypeId == "" || instance[0].TypeId == null) {
        alert("客户类型不能为空!");
        $('#TypeId').focus();
        return;
    }
    if (instance[0].TradeId == "" || instance[0].TradeId == null) {
        alert("所属行业不能为空!");
        $('#TradeId').focus();
        return;
    }
    if (instance[0].ProductId == "" || instance[0].ProductId == null) {
        alert("公司产值不能为空!");
        $('#ProductId').focus();
        return;
    }
    if (instance[0].OriginId == "" || instance[0].OriginId == null) {
        alert("客户来源不能为空!");
        $('#OriginId').focus();
        return;
    }
    if (instance[0].PropertyId == "" || instance[0].PropertyId == null) {
        alert("公司性质不能为空!");
        $('#PropertyId').focus();
        return;
    }
    /*if (instance[0].LevelId == "" || instance[0].LevelId == null) {
        alert("客户级别不能为空!");
        $('#LevelId').focus();
        return;
    }*/

    var json = $.toJSON(instance[0]).replace(/'/g, "[B]");
    $("#jsonDataContent").val(json);
    CheckData();
}
//保存数据验证
function CheckData() {
    var vName = $('#CustomerName').val();
    var vDecisionmaker = $('#Decisionmaker').val();
    var vDecisionTel = $('#DecisionTel').val();
    var vValue = vName + "," + vDecisionmaker + "," + vDecisionTel;
    YAHOO.util.Connect.asyncRequest('POST', Url + "?r=" + Math.random() + "&id=" + vid + "&temp=" + flag + "&entity=CustomerName&action=check&name=" + encodeURI(vValue) + "", //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
                if (str == "0") {   //失败
                    $('#CustomerName').focus();
                    document.getElementById("CustomerName").value = "";
                    return false;
                } else if (str == "1") {  //客户名已存在
                    //alert("该客户名称已经存在!");
                    SetMaxDWH(YAHOO.example.container.dialog1, 23, 200);
                    document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerShow&order=Code&ct=0&cn=" + encodeURI(vName);
                    YAHOO.example.container.dialog1.show();
                    document.getElementById("yui-gen0-button").style.display = "none";
                    $('#CustomerName').focus();
                    document.getElementById("CustomerName").value = "";
                    return false;
                } else if (str == "11") {
                    //alert("该客户名称已经存在!");
                    SetMaxDWH(YAHOO.example.container.dialog1, 23, 200);
                    document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerInfoSale&order=Code&ct=0&cn=" + encodeURI(vName);
                    YAHOO.example.container.dialog1.show();
                    document.getElementById("yui-gen0-button").style.display = "none";
                    $('#CustomerName').focus();
                    document.getElementById("CustomerName").value = "";
                    return false;
                } else if (str == "111") {  //客户名长度大8
                    if (saveState == 1) {
                        trySave();
                    } else {
                        saveState = 1;
                        var name = vName.substring(4, 8);
                        SetMaxDWH(YAHOO.example.container.dialog4, 23, 200);
                        document.getElementById("EditUIWindow4").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerShow&order=Code&ct=2&cn=" + encodeURI(name);
                        YAHOO.example.container.dialog4.show();
                        $('#CustomerName').focus();
                        return false;
                    }
                } else if (str == "1111") {  //客户名长度大于8
                    if (saveState == 1) {
                        trySave();
                    } else {
                        saveState = 1;
                        var name = vName.substring(4, 8);
                        SetMaxDWH(YAHOO.example.container.dialog4, 23, 200);
                        document.getElementById("EditUIWindow4").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerInfoSale&order=Code&ct=2&cn=" + encodeURI(name);
                        YAHOO.example.container.dialog4.show();
                        $('#CustomerName').focus();
                        return false;
                    }
                } else if (str == "3") {  //决策人和决策人手机已经存在
                    //alert("决策人手机已经存在!");
                    SetMaxDWH(YAHOO.example.container.dialog1, 23, 200);
                    document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerShow&order=Code&ct=1&cn=" + vDecisionTel;
                    YAHOO.example.container.dialog1.show();
                    document.getElementById("yui-gen0-button").style.display = "none";
                    $('#Decisionmaker').focus();
                    document.getElementById("DecisionTel").value = "";
                    return false;
                } else if (str == "33") {
                    //alert("决策人手机已经存在!");
                    SetMaxDWH(YAHOO.example.container.dialog1, 23, 200);
                    document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerInfoSale&order=Code&ct=1&cn=" + vDecisionTel;
                    YAHOO.example.container.dialog1.show();
                    document.getElementById("yui-gen0-button").style.display = "none";
                    $('#Decisionmaker').focus();
                    document.getElementById("DecisionTel").value = "";
                    return false;
                } else if (str == "4") {  //成功
                    trySave();
                } else if (str == "5") {
                    alert("您今天录入的客户总数已超过设置的客户总数，如有疑问请联系管理员!");
                    fnClose();
                    RefreshDataParent();
                }
            }
            catch (e) {
                return false;
            }
            finally {
            }
        }, failure: function () { }
    });
}
var trySave = function () {
    var formObject = document.getElementById('form2');
    YAHOO.util.Connect.setForm(formObject);
    var cObj = YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/DataSave.aspx?flag=1&action=" + action + "&entity=" + entity + "", callback);
}
var responseSuccess = function (res) {
    try {
        var str = res.responseText;
        if (str == "1") {
            btnState = 1; //保存成功后设置状态
            alert("数据保存成功");
            RefreshDataParent();
            if (flag == "1" || flag == "3") { //新增状态下保存后保存默认联系人,设置控件为只读
                GetCheckState();
                if (action == "insert") {
                    SavePrivateData();
                    SaveDefaultLinkMan();
                }
            } else { //修改状态 
                if (action == "update") {
                    trySaveCustomer();
                }
            }
        }
        else {
            alert("数据保存失败!");
        }
    } catch (e) {
    }
    finally {
    }
};
var responseFailure = function (error) {
    alert("数据错误：" + error.statusText);
}
var callback = {
    success: responseSuccess,
    failure: responseFailure
};


//联动更新保存客户数据
var trySaveCustomer = function () {
    var formObject = document.getElementById('form2');
    YAHOO.util.Connect.setForm(formObject);
    var cObj = YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/CustomOperating.aspx?flag=1&action=" + action + "&entity=CustomerUpdate", callbackCustomer);
}
var responseSuccessCustomer = function (res) {
    try {
        var str = res.responseText;
        if (str == "1") {
            fnClose();
        } else {
            //alert("联动更新客户数据失败!");
            //alert(str);
        }
    } catch (e) {
    }
    finally {
    }
};
var callbackCustomer = {
    success: responseSuccessCustomer,
    failure: responseFailure
};



//保存私海数据
var SavePrivateData = function () {
    var CustomId = $('#ID').val();  //客户ID
    var CustomerMrg = $("#CustomeerMgrs").val(); //客户经理ID
    var SaveUrl = Url + "?r=" + Math.random() + "&mrg=" + CustomerMrg + "&action=procedure&entity=CrmCustomerInfo&id=" + CustomId;
    YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "1") {
                    RefreshDataParent();
                } else {
                    alert("数据保存失败!");
                }
            }
            catch (e) {
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误1：" + error.statusText);
        }
    }, null);
}

//保存默认的联系人
var SaveDefaultLinkMan = function () {
    var elist = [{ "CustomId": "", "Caption": "", "TypeID": "", "Position": "", "DeptName": "", "Email": "", "Sex": "",
        "MobileTel": "", "Homeplace": "", "BirthdayType": "", "Birthday": "", "DecisionFancy": "",
        "EXP3": "", "EXP4": "", "Drink": ""
    }];
    elist[0].CustomId = instance[0].ID;
    elist[0].Caption = instance[0].Decisionmaker;
    elist[0].TypeID = "6783979d-a8fb-49fd-b8fb-8966a596db6e";
    elist[0].Position = instance[0].DecisionPosition;
    elist[0].DeptName = "";
    elist[0].Email = instance[0].DecisionEmail;
    elist[0].Sex = instance[0].DecisionSex;
    elist[0].MobileTel = instance[0].DecisionTel;
    elist[0].Homeplace = instance[0].Homeplace; //籍贯
    elist[0].BirthdayType = instance[0].BirthdayType; //生日类型
    elist[0].Birthday = instance[0].DecisionBirthday; //生日
    elist[0].DecisionFancy = instance[0].DecisionFancy; //爱好
    if (instance[0].DecisionBirthday == "" || instance[0].DecisionBirthday == "0001-01-01 ") {
        elist[0].Birthday = "1900-01-01";
    }
    elist[0].EXP3 = elist[0].Birthday.substring(0, 4);
    elist[0].EXP4 = elist[0].Birthday.substring(5, 7);
    elist[0].Drink = elist[0].Birthday.substring(8, 10);
    var jsonStr = YAHOO.lang.JSON.stringify(elist);
    var SaveUrl = Url + "?r=" + Math.random() + "&action=procedure&entity=CrmLinkMan&json=" + encodeURI(jsonStr.replace(/&/g, "[A]").replace(/'/g, "''"));
    YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "1") {
                    LoadLinkMan();
                }
            }
            catch (e) {
            }
            finally {


            }
        },
        failure: function (error) {
            alert("数据错误2：" + error.statusText);
        }
    }, null);
}
var LoadLinkMan = function () {
    var vc = "CustomId='" + vid + "'";
    YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=V_CrmManager&order=AddTime&customCondition=" + vc + "", //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
                SetFormValue1(str);
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
    });
}
var LoadActivity = function () {
    var vc = "CustomId='" + vid + "' and (AnticipeResult is not null or AnticipeResult<>'')";
    YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&order=AddTime&entity=V_CrmActivityCall&customCondition=" + vc + "", //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
                SetFormValue6(str);
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
    });
}
var LoadAttach = function () {
    YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/CustomOperating.aspx?r=" + Math.random() + "&type=1&order=AddTime&entity=CrmCustomerAttach&id=" + vid, //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
                SetFormValue3(str);
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
    });
}
var LoadCustomerRelation = function () {
    var vc = "CustomerID='" + vid + "'";
    YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=V_CrmCustomerRelationInfo&order=AddTime&customCondition=" + vc + "", //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
                SetFormValue9(str);
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
    });
}
//加载公开课数据
var LoadDeliverMajor = function () {
    var vc = "CustomerId='" + vid + "'";
    YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=V_CrmDeliverMajor&order=AddTime&customCondition=" + vc + "", //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
                SetFormValue10(str);
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
    });
}
//加载内训数据
var LoadDeliverTrain = function () {
    var vc = "CustomerId='" + vid + "'";
    YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=V_CrmDeliverTrain&order=AddTime&customCondition=" + vc + "", //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
                SetFormValue11(str);
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
    });
}
//加载项目数据
var LoadDeliverProInfo = function () {
    var vc = "CustomerId='" + vid + "'";
    YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=V_CrmDeliverMajorProInfo&order=AddTime&customCondition=" + vc + "", //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
                SetFormValue12(str);
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
    });
}



//联系人双击事件
var onRowDoubleClickLinkMan = function () {
    if (flag != "0") {   //0:查看状态
    }
    var recordID = mDataTable1.getSelectedRows()[0];
    var record = mDataTable1.getRecord(recordID);
    var id = record.getData("ID");
    var adduser = record.getData("AddUser");
    if (id == "") {  //新增
        var pagetitle = "新增联系人信息";
        parent.addTabs(pagetitle, 'Crm/Customer/EditCrmManager.aspx?cid=' + vid + '');
        parent.NeedRefreshPage = this;
    } else {  //修改(添加联系人详细信息)
        if (userid == adduser) {
            var pagetitle = "编辑联系人信息";
            parent.addTabs(pagetitle, 'Crm/Customer/EditCrmManager.aspx?cid=' + vid + '&id=' + id + '');
            parent.NeedRefreshPage = this;
        } else {
            alert("当前记录添加人不是您本人,您无权双击修改操作!");
            return;
        }
    }
}
//商机任务记录双击事件
var onRowDoubleClickActivity = function () {
    if (flag != "0") {   //0:查看状态
    }
    var recordID = mDataTable6.getSelectedRows()[0];
    var record = mDataTable6.getRecord(recordID);
    var id = record.getData("ID");
    var adduser = record.getData("AddUser");
    if (id == "") {  //新增
        var pagetitle = "新增工作记录";
        parent.addTabs(pagetitle, 'Crm/Customer/EditCrmCallOn.aspx');
        parent.NeedRefreshPage = this;
    } else {  //修改(添加联系人详细信息)
        if (userid == adduser) {
            var pagetitle = "编辑工作记录";
            parent.addTabs(pagetitle, 'Crm/Customer/EditCrmCallOn.aspx?edit=0&id=' + id + '&cid=' + vid + '');
            parent.NeedRefreshPage = this;
        } else {
            alert("当前记录添加人不是您本人,您无权双击修改操作!");
            return;
        }
    }
}
//订单双击事件
var onRowDoubleClickOrder = function () {
    var recordID = mDataTable4.getSelectedRows()[0];
    var record = mDataTable4.getRecord(recordID);
    var typeId = record.getData("TypeID");
    var id = record.getData("ID");
    if (id != "") {
        if (typeId == "5e50217a-414e-46d5-89bc-348ad0145ffc") { //约场
            window.parent.$("#tabs").tabs('close', '查看约场订单');
            var pagetitle = "查看约场订单";
            parent.addTabs(pagetitle, '../Crm/Sale/AddOrderField.aspx?flag=5&id=' + id + '&entity=CrmCustomerOrder&title=' + encodeURI(pagetitle));
            parent.NeedRefreshPage = this;
        } else {
            window.parent.$("#tabs").tabs('close', '查看销售订单');
            var pagetitle = "查看销售订单";
            parent.addTabs(pagetitle, '../Crm/Sale/AddOrder.aspx?flag=4&id=' + id + '&entity=CrmCustomerOrder&title=' + encodeURI(pagetitle));
            parent.NeedRefreshPage = this;
        }
    }
}
//缴款单双击事件
var onRowDoubleClickPay = function () {
    var recordID = mDataTable5.getSelectedRows()[0];
    var record = mDataTable5.getRecord(recordID);
    var id = record.getData("ID");
    if (id != "") {
        window.parent.$("#tabs").tabs('close', '查看缴款单信息');
        var pagetitle = "查看缴款单信息";
        parent.addTabs(pagetitle, '../Crm/Modules/AddPay.aspx?r=' + Math.random() + '&view=checks&flag=1&entity=CrmPay&id=' + id + '');
        parent.NeedRefreshPage = this;
    }
}
//讲师总结双击事件
var onRowDoubleClickTeachSump = function () {
    var recordID = mDataTable7.getSelectedRows()[0];
    var record = mDataTable7.getRecord(recordID);
    var id = record.getData("ThodometerId");
    if (id != "") {
        var pagetitle = "讲师总结";
        parent.addTabs(pagetitle, 'Crm/Sale/AddTeachSumup.aspx?type=1&ID=' + id + '');
        parent.NeedRefreshPage = this;
    }
}
//客户关系列表双击事件
var onRowDoubleClickCustomerRelation = function () {
    var recordID = mDataTable9.getSelectedRows()[0];
    var record = mDataTable9.getRecord(recordID);
    var id = record.getData("ID");
    var adduser = record.getData("AddUser");
    if (userid == adduser) {
        if (id != "") {
            document.getElementById("EditUIWindow3").src = "../../Crm/Customer/AddCustomerRelation.aspx?r=" + Math.random() + "&type=1&rid=" + id + "&id=" + vid;
            YAHOO.example.container.dialog3.show();
        }
    } else {
        alert("当前记录添加人不是您本人,您无权双击修改操作!");
        return;
    }
}
//公开课双击事件
var onRowDoubleClickDeliverMajor = function () {
    var recordID = mDataTable10.getSelectedRows()[0];
    var record = mDataTable10.getRecord(recordID);
    var cid = record.getData("WorkFlowInsId");
    if (cid != "") {
        window.parent.$("#tabs").tabs('close', '查看交付申请单--公开课');
        var pagetitle = "查看交付申请单--公开课";
        parent.addTabs(pagetitle, '../Crm/Deliver/AddDeliverMajor.aspx?r=' + Math.random() + '&view=check&flag=1&entity=CrmDeliverMajor&id=' + cid + '&title=' + encodeURI(pagetitle));
        parent.NeedRefreshPage = this;
    }
}
//内训双击事件
var onRowDoubleClickDeliverTrain = function () {
    var recordID = mDataTable11.getSelectedRows()[0];
    var record = mDataTable11.getRecord(recordID);
    var cid = record.getData("WorkFlowInsId");
    if (cid != "") {
        window.parent.$("#tabs").tabs('close', '查看交付申请单--内训');
        var pagetitle = "查看交付申请单--内训";
        parent.addTabs(pagetitle, '../Crm/Deliver/AddDeliverTrain.aspx?r=' + Math.random() + '&view=check&flag=1&entity=CrmDeliverTrain&id=' + cid + '&title=' + encodeURI(pagetitle));
        parent.NeedRefreshPage = this;
    }
}
//项目双击事件
var onRowDoubleClickDeliverProInfo = function () {
    var recordID = mDataTable12.getSelectedRows()[0];
    var record = mDataTable12.getRecord(recordID);
    var cid = record.getData("WorkFlowInsId");
    if (cid != "") {
        window.parent.$("#tabs").tabs('close', '查看交付申请单--项目');
        var pagetitle = "查看交付申请单--项目";
        parent.addTabs(pagetitle, '../Crm/Deliver/AddDeliverMajorProject.aspx?r=' + Math.random() + '&view=check&flag=1&entity=CrmDeliverMajorProInfo&id=' + cid + '&title=' + encodeURI(pagetitle));
        parent.NeedRefreshPage = this;
    }
}




//刷新父窗体数据
function RefreshDataParent() {
    if (parent.NeedRefreshPage != null) {
        if (typeof (parent.NeedRefreshPage.LoadData) == "function") {
            parent.NeedRefreshPage.RefreshData();
        }
    }
}
//修改按钮事件
var Modify = function () {
    fnModify0();
}
var fnModify0 = function () {
    window.parent.$("#tabs").tabs('close', '修改客户信息');
    var pagetitle = "修改客户信息";
    parent.addTabs(pagetitle, '../Crm/Customer/AddCustomerInfo.aspx?r=' + Math.random() + '&type=0&flag=2&entity=' + entity + '&id=' + vid + '&title=' + encodeURI(pagetitle));
    parent.NeedRefreshPage = this;
    fnClose();
}

//添加联系人
var ShowLinkMan = function () {
    if (flag == "1" && btnState == 0) {
        alert("请先保存客户资料后添加联系人!");
        return;
    } else {
        document.getElementById("EditUIWindow3").src = "../../Crm/Customer/AddLinkMan.aspx?r=" + Math.random() + "&id=" + vid;
        YAHOO.example.container.dialog3.show();
    }
}
//删除联系人
var DeleteLinkMan = function () {
    if (flag == "1" && btnState == 0) {
        alert("请先保存客户资料后添加联系人!");
        return;
    } else {
        var recordID = mDataTable1.getSelectedRows()[0];
        if (recordID != null && recordID.length != 1) {
            record = mDataTable1.getRecord(recordID);
            var vid = record.getData("ID");
            var adduser = record.getData("AddUser");
            if (userid == adduser) {
                if (vid != "") {
                    if (vid == "00000000-0000-0000-0000-000000000000") {
                        mDataTable1.deleteRow(recordID);
                    } else {
                        if (confirm("您确定删除该行吗?")) {
                            var SaveUrl = Url + "?r=" + Math.random() + "&action=delete&entity=CrmLinkMan&json=&id=" + vid;
                            YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
                                success: function (res) {
                                    try {
                                        var str = res.responseText;
                                        if (str == "1") {
                                            alert("联系人删除成功!");
                                            mDataTable1.deleteRow(recordID);
                                        }
                                        else {
                                            alert(str + "\n" + "数据删除失败!");
                                        }
                                    }
                                    catch (e) {
                                    }
                                    finally {
                                    }
                                },
                                failure: function (error) {
                                    alert("数据错误：" + error.statusText);
                                }
                            }, null);
                        }
                    }
                } else {
                    mDataTable1.deleteRow(recordID);
                }
            } else {
                alert("当前记录添加人不是您本人,您无权操作!");
                return;
            }
        } else {
            alert("请选中一行后删除！");
        }
    }
}
//添加商机任务记录
var ShowActivity = function () {
    if (flag == "1" && btnState == 0) {
        alert("请先保存客户资料后添加联系人!");
        return;
    } else {
        document.getElementById("EditUIWindow3").src = "../../Crm/Customer/AddActivityInfo.aspx?r=" + Math.random() + "&id=" + vid;
        YAHOO.example.container.dialog3.show();
    }
}
//删除商机任务记录
var DeleteActivity = function () {
    if (flag == "1" && btnState == 0) {
        alert("请先保存客户资料后添加联系人!");
        return;
    } else {
        var recordID = mDataTable6.getSelectedRows()[0];
        if (recordID != null && recordID.length != 1) {
            record = mDataTable6.getRecord(recordID);
            var vid = record.getData("ID");
            var adduser = record.getData("AddUser");
            if (userid == adduser) {
                if (vid != "") {
                    if (vid == "00000000-0000-0000-0000-000000000000") {
                        mDataTable6.deleteRow(recordID);
                    } else {
                        if (confirm("您确定删除该行吗?")) {
                            var SaveUrl = Url + "?r=" + Math.random() + "&action=delete&entity=CrmActivity&json=&id=" + vid;
                            YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
                                success: function (res) {
                                    try {
                                        var str = res.responseText;
                                        if (str == "1") {
                                            alert("工记录删除成功!");
                                            mDataTable6.deleteRow(recordID);
                                        }
                                        else {
                                            alert(str + "\n" + "数据删除失败!");
                                        }
                                    }
                                    catch (e) {
                                    }
                                    finally {
                                    }
                                },
                                failure: function (error) {
                                    alert("数据错误：" + error.statusText);
                                }
                            }, null);
                        }
                    }
                } else {
                    mDataTable6.deleteRow(recordID);
                }
            } else {
                alert("当前记录添加人不是您本人,您无权操作!");
                return;
            }
        } else {
            alert("请选中一行后删除！");
        }
    }
}
//添加附件
var ShowAttach = function () {
    if (flag == "1" && btnState == 0) {
        alert("请先保存客户资料后添加联系人!");
        return;
    } else {
        document.getElementById("EditUIWindow2").src = "../AddAttach.aspx?id=" + vid;
        YAHOO.example.container.dialog2.show();
    }
}
//删除附件
var DeleteAttach = function () {
    if (flag == "1" && btnState == 0) {
        alert("请先保存客户资料后添加联系人!");
        return;
    } else {
        var recordID = mDataTable3.getSelectedRows()[0];
        if (recordID != null && recordID.length != 1) {
            record = mDataTable3.getRecord(recordID);
            var vAttachId = record.getData("ID");
            var adduser = record.getData("AddUser");
            if (userid == adduser) {
                var ListId = "";
                var list = mDataTable3.getRecordSet()._records;
                for (var i = 0; i < list.length; i++) {
                    if (list[i]._oData.ID != vAttachId) {
                        if (list[i]._oData.ID == "" || list[i]._oData.ID == null) {
                            list[i]._oData.ID = "00000000-0000-0000-0000-000000000000";
                        }
                        ListId += list[i]._oData.ID + ",";
                    }
                }
                if (vAttachId != "") {
                    if (vid == "00000000-0000-0000-0000-000000000000") {
                        mDataTable3.deleteRow(recordID);
                    } else {
                        if (confirm("您确定删除该行吗?")) {
                            var SaveUrl = Url + "?r=" + Math.random() + "&action=delete&entity=CrmCustomerAttach&id=" + vid + "&listId=" + encodeURI(ListId.replace(/&/g, "[A]").replace(/'/g, "''")) + "&aid=" + vAttachId;
                            YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
                                success: function (res) {
                                    try {
                                        var str = res.responseText;
                                        if (str == "1") {
                                            alert("附件删除成功!");
                                            mDataTable3.deleteRow(recordID);
                                        }
                                        else {
                                            alert(str + "\n" + "数据删除失败!");
                                        }
                                    }
                                    catch (e) {
                                    }
                                    finally {
                                    }
                                },
                                failure: function (error) {
                                    alert("数据错误：" + error.statusText);
                                }
                            }, null);
                        }
                    }
                } else {
                    mDataTable2.deleteRow(recordID);
                }
            } else {
                alert("当前记录添加人不是您本人,您无权操作!");
                return;
            }
        } else {
            alert("请选中一行后删除！");
        }
    }
}

//新增客户关系
var ShowCustomerRelation = function () { 
    if (flag == "1" && btnState == 0) {
        alert("请先保存客户资料后添加客户关系!");
        return;
    } else {
        document.getElementById("EditUIWindow3").src = "../../Crm/Customer/AddCustomerRelation.aspx?r=" + Math.random() + "&id=" + vid;
        YAHOO.example.container.dialog3.show();
    }
}
//删除客户关系
var DeleteCustomerRelation = function () {
    if (flag == "1" && btnState == 0) {
        alert("请先保存客户资料后添加联系人!");
        return;
    } else {
        var recordID = mDataTable9.getSelectedRows()[0];
        if (recordID != null && recordID.length != 1) {
            record = mDataTable9.getRecord(recordID);
            var vRelationId = record.getData("ID");
            var adduser = record.getData("AddUser");
            if (userid == adduser) {
                if (confirm("您确定删除该行吗?")) {
                    var SaveUrl = Url + "?r=" + Math.random() + "&action=delete&entity=CrmCustomerRelation&id=" + vRelationId;
                    YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
                        success: function (res) {
                            try {
                                var str = res.responseText;
                                if (str == "1") {
                                    alert("客户关系信息成功!");
                                    mDataTable9.deleteRow(recordID);
                                }
                                else {
                                    alert("数据删除失败!");
                                }
                            }
                            catch (e) {
                            }
                            finally {
                            }
                        },
                        failure: function (error) {
                            alert("数据错误：" + error.statusText);
                        }
                    }, null);
                }
            } else {
                alert("当前记录添加人不是您本人,您无权操作!");
                return;
            }
        } else {
            alert("请选中一行后删除！");
        }
    }
}